package com.turnengine.client.global.admin.command;

import org.apache.commons.lang.builder.CompareToBuilder;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * The Send Email.
 */
public class SendEmail implements ISendEmail {

	/** The command id. */
	public static final short COMMAND_ID = 602;

	/** The login id. */
	private long loginId;
	/** The sender. */
	private String sender;
	/** The recipient. */
	private String recipient;
	/** The subject. */
	private String subject;
	/** The body. */
	private String body;

	/**
	 * Creates a new Send Email.
	 */
	public SendEmail() {
	}

	/**
	 * Creates a new Send Email.
	 * @param loginId the login id
	 * @param sender the sender
	 * @param recipient the recipient
	 * @param subject the subject
	 * @param body the body
	 */
	public SendEmail(long loginId, String sender, String recipient, String subject, String body) {
		setLoginId(loginId);
		setSender(sender);
		setRecipient(recipient);
		setSubject(subject);
		setBody(body);
	}

	/**
	 * Creates a new Send Email.
	 * @param iSendEmail the i send email
	 */
	public SendEmail(ISendEmail iSendEmail) {
		setLoginId(iSendEmail.getLoginId());
		setSender(iSendEmail.getSender());
		setRecipient(iSendEmail.getRecipient());
		setSubject(iSendEmail.getSubject());
		setBody(iSendEmail.getBody());
	}

	/**
	 * Returns the login id.
	 * @return the login id.
	 */
	public long getLoginId() {
		return loginId;
	}

	/**
	 * Returns the sender.
	 * @return the sender.
	 */
	public String getSender() {
		return sender;
	}

	/**
	 * Returns the recipient.
	 * @return the recipient.
	 */
	public String getRecipient() {
		return recipient;
	}

	/**
	 * Returns the subject.
	 * @return the subject.
	 */
	public String getSubject() {
		return subject;
	}

	/**
	 * Returns the body.
	 * @return the body.
	 */
	public String getBody() {
		return body;
	}

	/**
	 * Sets the login id.
	 * @param loginId the login id to set.
	 */
	public void setLoginId(long loginId) {
		this.loginId = loginId;
	}

	/**
	 * Sets the sender.
	 * @param sender the sender to set.
	 */
	public void setSender(String sender) {
		if (sender == null) {
			throw new NullPointerException("sender");
		}
		this.sender = sender;
	}

	/**
	 * Sets the recipient.
	 * @param recipient the recipient to set.
	 */
	public void setRecipient(String recipient) {
		if (recipient == null) {
			throw new NullPointerException("recipient");
		}
		this.recipient = recipient;
	}

	/**
	 * Sets the subject.
	 * @param subject the subject to set.
	 */
	public void setSubject(String subject) {
		if (subject == null) {
			throw new NullPointerException("subject");
		}
		this.subject = subject;
	}

	/**
	 * Sets the body.
	 * @param body the body to set.
	 */
	public void setBody(String body) {
		if (body == null) {
			throw new NullPointerException("body");
		}
		this.body = body;
	}

	/**
	 * Returns the hash code.
	 * @return the hash code.
	 */
	@Override
	public int hashCode() {
		HashCodeBuilder hash = new HashCodeBuilder(3, 37);
		hash.append(loginId);
		hash.append(sender);
		hash.append(recipient);
		hash.append(subject);
		hash.append(body);
		return hash.toHashCode();
	}

	/**
	 * Returns true if this is equal to the given object.
	 * @param object the object to compare.
	 * @return true if this is equal to the given object.
	 */
	@Override
	public boolean equals(Object object) {
		if (object == this) {
			return true;
		}
		if (object instanceof SendEmail) {
			SendEmail compare = (SendEmail) object;
			EqualsBuilder equals = new EqualsBuilder();
			equals.append(this.loginId, compare.loginId);
			equals.append(this.sender, compare.sender);
			equals.append(this.recipient, compare.recipient);
			equals.append(this.subject, compare.subject);
			equals.append(this.body, compare.body);
			return equals.isEquals();
		}
		return false;
	}

	/**
	 * Compare this to the given object.
	 * @param compare the object to compare to.
	 * @return the result of the comparison.
	 */
	@Override
	public int compareTo(ISendEmail compare) {
		CompareToBuilder builder = new CompareToBuilder();
		builder.append(this.loginId, compare.getLoginId());
		builder.append(this.sender, compare.getSender());
		builder.append(this.recipient, compare.getRecipient());
		builder.append(this.subject, compare.getSubject());
		builder.append(this.body, compare.getBody());
		return builder.toComparison();
	}

	/**
	 * Returns this as a string.
	 * @return this as a string.
	 */
	@Override
	public String toString() {
		ToStringBuilder string = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
		string.append("loginId", loginId);
		if (sender != null) {
			string.append("sender", sender);
		}
		if (recipient != null) {
			string.append("recipient", recipient);
		}
		if (subject != null) {
			string.append("subject", subject);
		}
		if (body != null) {
			string.append("body", body);
		}
		return string.toString();
	}

	public short getCommandId() {
		return COMMAND_ID;
	}
}
